package com.ly.heart.service.impl;

import com.ly.common.exception.CustomException;
import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.common.utils.erp.SnowflakeIdWorker;
import com.ly.heart.domain.KingDiffLogEntity;
import com.ly.heart.mapper.KingDiffLogMapper;
import com.ly.heart.service.IKingDiffLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.heart.util.CurrentUserUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 金蝶-差异日志 服务实现类
 * </p>
 *
 * @author WuZH
 * @since 2024-07-30
 */
@Service
public class KingDiffLogServiceImpl extends ServiceImpl<KingDiffLogMapper, KingDiffLogEntity> implements IKingDiffLogService {

    @Resource
    private KingDiffLogMapper kingDiffLogMapper;

    @Override
    public KingDiffLogEntity saveSingle ( KingDiffLogEntity kingDiffLogEntity ) {
        if ( kingDiffLogEntity == null ) {
            throw new CustomException ( "对象不能为空！" );
        }
        kingDiffLogEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        kingDiffLogEntity.setVerifyDate ( DateUtils.getNowDate () );
        kingDiffLogEntity.setDeptId ( CurrentUserUtil.getCompanyId () );
        kingDiffLogEntity.setCreateBy ( SecurityUtils.getLoginUser ().getUser ().getUserId () );
        kingDiffLogEntity.setCreateTime ( DateUtils.getNowDate () );
        boolean save = this.save ( kingDiffLogEntity );
        if ( ! save ) {
            throw new CustomException ( "新增差异日志失败！" );
        }
        return kingDiffLogEntity;
    }

    @Override
    public List<KingDiffLogEntity> queryList ( KingDiffLogEntity kingDiffLogEntity ) {
        kingDiffLogEntity.setPage ( ( kingDiffLogEntity.getPage () - 1 ) * kingDiffLogEntity.getLimit () );
        List<KingDiffLogEntity> kingDiffLogEntities = kingDiffLogMapper.queryList ( kingDiffLogEntity );
        return kingDiffLogEntities;
    }

    @Override
    public Integer queryCount ( KingDiffLogEntity kingDiffLogEntity ) {
        Integer integer = kingDiffLogMapper.queryCount ( kingDiffLogEntity );
        return integer;
    }
}
